package com.core.reach.cloudhub.service.impl;

import com.core.reach.cloudhub.dao.AccountMapper;
import com.core.reach.cloudhub.service.AccountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @author ga.zhang
 * @version V1.0
 * @description: TODO
 * @date 2020/4/1 16:07
 **/
@Service("accountService")
public class AccountServiceImpl implements AccountService {

    private static final Logger LOGGER = LoggerFactory.getLogger(AccountServiceImpl.class);

    @Resource
    private AccountMapper accountMapper;

    @Override
    public Boolean reduceAccount(Long userId, BigDecimal money) {
        LOGGER.info("------->storage-service中扣减余额开始");
        Boolean isReduce =  accountMapper.reduceAccount(userId, money) > 0;
        if (isReduce) {
            LOGGER.info("------->storage-service中扣减余额成功");
        } else {
            LOGGER.info("------->storage-service中扣减余额失败");
        }
        return isReduce;
    }
}
